layui.define(['table', 'form'], function(exports){
	var $ = layui.$
		,admin = layui.admin
		,view = layui.view
		,table = layui.table
		,form = layui.form
		,util = layui.util;

	//列表
	let app='store';
	table.render({
		elem: '#LAY-user-back-manage'
		,url: './'+app+'/list' //id,email,mall_id as mall_name,gapday,name,url,img,status,createtime
		,toolbar: '#toolbar'
		,defaultToolbar: ['filter', 'exports', 'print']
		//,editTrigger: 'dblclick' // 触发编辑的事件类型（默认 click ）。 v2.7.0 新增，之前版本固定为单击触发
		,cols: [[
			{type: 'checkbox', fixed: 'left'},
			{field: 'id', width: 80, title: 'ID'}
			,{field: 'name', title: '店铺名称'}
			,{field: 'mall_name', title: '平台'}
			,{field: 'email', title: '所属商家'}
			,{field: 'img', title: '后台截图', templet: '#imgTpl'}
			,{field: 'url', title: '店铺链接'}
			,{field: 'gapday', title: '控制接单间隔(天)'}
			,{field: 'createtime', title: '添加时间'}
			,{field: 'status', title: '审核状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
			,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
		]]
		,text: '对不起，加载出现异常！'
		,page: true
		,limit: 30
		,height: 'full-320'
		,lineStyle: 'height: 95px;'
		,done: function(){

		}
		,error: function(res, msg){
			console.log(res, msg)
		}
	});

	//工具条
	table.on('tool(LAY-user-back-manage)', function(obj){
		var data = obj.data;
		if(obj.event === 'edit'){
			admin.popup({
				title: '编辑店铺'
				,area: ['420px', '450px']
				,id: 'LAY-popup-user-add'
				,success: function(layero, index){
					view(this.id).render('store/info', data).done(function(){
						form.render(null, 'layuiadmin-form-admin');

						//提交
						form.on('submit(LAY-user-back-submit)', function(data){

							//提交 Ajax 成功后，关闭当前弹层并重载表格
							admin.req({
								url: './store/edit'
								,type: 'post'
								,data: data.field
								,done: function(res){
									layui.table.reload('LAY-user-back-manage'); //重载表格
									layer.close(index); //执行关闭
								}
							});

						});

					});
				}
			});
		}
	});

	exports(app, {})
});

